<?php


namespace App\Models\CacheModel;


use App\Models\Api\BaseCache;
use AstroTool\Cache\CacheManage;

class ZlFortuneSharePhoto extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl_fortune_share_photo';

    protected $cacheModel = 'fortune.share_photo';

    /**
     * 获取分享图片
     * @param int $type 1=>运势分享风格1  2=>运势分享风格3
     * @return array|mixed
     * @throws \Exception
     */
    public function getSharePhoto(int $type)
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $type)->getDataAndSet(function () use ($type)
        {
            try
            {
                $data = $this->where('type', $type)->where('status', 1)->order('sort desc')->select();

                return $data ? json_encode($data) : '';
            }
            catch (\Exception $e)
            {
                return '';
            }
        });

        return $data ? json_decode($data, true) : [];
    }
}
